//
//  RCCardTypeInfoDataModel.m
//  RocketProject
//
//  Created by chen jiedan on 13-9-16.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCCardTypeInfoDataModel.h"
#import "KFObjectExtension.h"

@implementation RCCardTypeIntroduce

@synthesize type = _type;
@synthesize title= _title;
@synthesize content=_content;

- (void) dealloc
{
    [_title release];
    [_content release];
    [super dealloc];
}

- (void) parseDic:(NSDictionary *)dic
{
    self.type = [dic intValueForKey:@"id" defaultValue:0];
    self.title= [dic stringValueForKey:@"title" defaultValue:@"" operation:NSStringOperationTypeNone];
    self.content= [dic stringValueForKey:@"content" defaultValue:@"" operation:NSStringOperationTypeNone];
}

@end


@implementation RCCardTypeInfo

@synthesize type = _type;
@synthesize title= _title;
@synthesize subtitle= _subtitle;
@synthesize content = _content;
@synthesize picUrl  = _picUrl;
- (void) dealloc
{
    [_title release];
    [_subtitle release];
    [_content release];
    [_picUrl release];
    [super dealloc];
}

- (void) parseDic:(NSDictionary *)dic
{
    self.type = [dic intValueForKey:@"cardid" defaultValue:0];
    self.title= [dic stringValueForKey:@"title" defaultValue:@"" operation:NSStringOperationTypeNone];
    self.subtitle= [dic stringValueForKey:@"subtitle" defaultValue:@"" operation:NSStringOperationTypeNone];
    self.picUrl= [dic stringValueForKey:@"picurl" defaultValue:@"" operation:NSStringOperationTypeNone];
    self.content= [dic stringValueForKey:@"content" defaultValue:@"" operation:NSStringOperationTypeNone];
}
@end


@implementation RCCardTypeInfoDataModel
@synthesize cardIntroduceArray = _cardIntroduceArray;
@synthesize cardTypeInfoArray  = _cardTypeInfoArray;

+(id)parseDataFromJSON:(NSDictionary *)data
{
    if (nil == data) {
        return nil;
    }
    NSArray *dictArray = [data arrayValueForKey:@"data" defaultValue:nil];
    if (nil == dictArray) {
        return nil;
    }
    RCCardTypeInfoDataModel *retObject = nil;
    retObject = [[[RCCardTypeInfoDataModel alloc]init] autorelease];
    
    for (NSDictionary *dic in dictArray) {
        NSArray *items = [dic arrayValueForKey:@"items" defaultValue:nil];
        for (NSDictionary *subItemDic in items) {
            if ([[dic stringValueForKey:@"type" defaultValue:@"" operation:NSStringOperationTypeNone] isEqualToString:@"领取会员卡说明"]) {
                RCCardTypeIntroduce *introduce = [[RCCardTypeIntroduce alloc] init];
                [introduce parseDic:subItemDic];
                [retObject.cardIntroduceArray addObject:introduce];
                [introduce release];
                
            }else if ([[dic stringValueForKey:@"type" defaultValue:@"" operation:NSStringOperationTypeNone] isEqualToString:@"会员卡列表"]) {
                RCCardTypeInfo *info = [[RCCardTypeInfo alloc] init];
                [info parseDic:subItemDic];
                [retObject.cardTypeInfoArray addObject:info];
                [info release];
            }
        }
    }
    
    return retObject;
}


- (NSMutableArray *) cardIntroduceArray
{
    if (_cardIntroduceArray == nil) {
        _cardIntroduceArray = [[NSMutableArray alloc] init];
    }
    return _cardIntroduceArray;
}


- (NSMutableArray *) cardTypeInfoArray
{
    if (_cardTypeInfoArray == nil) {
        _cardTypeInfoArray = [[NSMutableArray alloc] init];
    }
    return _cardTypeInfoArray;
}

- (void) dealloc
{
    [_cardTypeInfoArray release];
    [_cardIntroduceArray release];
    [super dealloc];
}
@end
